import 'package:flutter/material.dart';
import 'package:flutter_learning/charts/bar_chart_sample2.dart';
import 'package:flutter_learning/charts/line_chart_sample1.dart';
import 'package:flutter_learning/charts/ly_bar_chart_view.dart';
import 'package:flutter_learning/charts/ly_pie_chart_view.dart';
import 'package:flutter_learning/charts/pie_chart_sample2.dart';

class ChartsView extends StatefulWidget {
  const ChartsView({super.key});

  @override
  State<ChartsView> createState() => _ChartsViewState();
}

class _ChartsViewState extends State<ChartsView> {
  List<LYPieChartDataItem> pieItems = [];
  List<LYBarChartData> barDatas = [];

  @override
  void initState() {
    super.initState();
    for (int i = 0; i < 5; i++) {
      pieItems.add(
        LYPieChartDataItem(name: "测试$i", value: i * 10),
      );
    }

    for (int i = 0; i < 5; i++) {
      barDatas.add(
        LYBarChartData(
            title: "测试$i",
            rodDataList: [LYBarChartRodData(toY: i * 10), LYBarChartRodData(toY: i * 5)]),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("charts"),
        centerTitle: true,
      ),
      body: SafeArea(
        child: SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              SizedBox(
                height: 300,
                child: LYPieChartView(title: "饼图", dataItems: pieItems),
              ),
              SizedBox(
                height: 300,
                child: LineChartSample1(),
              ),
              SizedBox(
                height: 300,
                child: BarChartSample2(),
              ),
              SizedBox(
                height: 300,
                child: PieChartSample2(),
              ),
              SizedBox(
                height: 300,
                child: LYBarChartView(
                  title: '抓状图',
                  chartDataItems: barDatas,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
